package com.ycsj.goldmedalnewconcept.common.activity;

import android.support.v4.app.Fragment;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.ycsj.common.adapter.VpCommonAdapter;
import com.ycsj.common.base.BaseActivity;
import com.ycsj.common.utils.UiUtils;
import com.ycsj.common.view.vp.NoScrollViewPager;
import com.ycsj.goldmedalnewconcept.R;
import com.ycsj.goldmedalnewconcept.common.fragment.InviteFragment;
import com.ycsj.goldmedalnewconcept.common.util.LpUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 邀请好友
 * Created by Administrator on 2019/4/16 0016.
 */

public class InviteFriendActivity extends BaseActivity {

    @BindView(R.id.lv_edit)
    ImageView lvEdit;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    //已加盟
    @BindView(R.id.tv_yjm)
    TextView tvYjm;
    //已加盟的线性布局
    @BindView(R.id.ll_yjm)
    LinearLayout llYjm;
    //全部
    @BindView(R.id.tv_qb)
    TextView tvQb;
    @BindView(R.id.ll_qb)
    LinearLayout llQb;
    @BindView(R.id.vp)
    NoScrollViewPager vp;
    @BindView(R.id.ll_content)
    LinearLayout llContent;
    @BindView(R.id.rl_loading)
    RelativeLayout rlLoading;

    //填充ViewPager的页面
    private List<Fragment> mFragments;

    //ViewPager的适配器
    private VpCommonAdapter vpAdapter;


    //Tab页面选中的资源图片集合
    private int[] tabSelectIds = {R.drawable.teacher_student_select, R.drawable.teacher_class_select};

    //Tab页面未选中的资源图片集合
    private int[] tabUnselectIds = {R.drawable.teacher_student_normal, R.drawable.teacher_class_analy_normal};

    @Override
    protected int getContentLayout() {
        return R.layout.activity_invite_friend;
    }

    @Override
    protected void init() {
        initStateBar();

        //初始化标题
        initTitle();

        //初始化Vp
        initVp();
    }

    /**
     * 初始化标题栏
     */
    private void initTitle() {
        tvTitle.setText("邀请好友");
        vp.setPagerEnabled(false);

        RelativeLayout.LayoutParams lp = LpUtils.getRelatLp(UiUtils.dp2px(72), UiUtils.dp2px(36));
        lp.addRule(RelativeLayout.CENTER_VERTICAL);
        lp.leftMargin = 16;
        lvEdit.setLayoutParams(lp);
        lvEdit.setImageResource(R.drawable.invite);
        lvEdit.setVisibility(View.VISIBLE);
    }

    /**
     * 初始化VieWPager
     */
    private void initVp() {
        rlLoading.setVisibility(View.GONE);
        mFragments = new ArrayList<>();
        mFragments.add(InviteFragment.newInstance());
        mFragments.add(InviteFragment.newInstance());
        vpAdapter = new VpCommonAdapter(getSupportFragmentManager(), mFragments);
        vp.setOffscreenPageLimit(mFragments.size());
        vp.setAdapter(vpAdapter);
    }

    /**
     * 同步ViewPager页面和切换选中Tab的方法
     *
     * @param pos
     */
    private void syncVpState(int pos) {
        vp.setCurrentItem(pos);
        if (pos == 0) {
            llQb.setBackgroundResource(tabSelectIds[0]);
            llYjm.setBackgroundResource(tabUnselectIds[1]);
        } else if (pos == 1) {
            llQb.setBackgroundResource(tabUnselectIds[0]);
            llYjm.setBackgroundResource(tabSelectIds[1]);
        }
    }

    /**
     * 点击事件
     *
     * @param view
     */
    @OnClick({R.id.iv_back, R.id.ll_qb, R.id.ll_yjm, R.id.lv_edit})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                finish();
                break;
            case R.id.ll_qb:
                syncVpState(0);
                break;
            case R.id.ll_yjm:
                syncVpState(1);
                break;
            case R.id.lv_edit:
                //邀请
                break;

        }
    }

}
